home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-12 | 2.9 KB | 171 lines | [TEXT/KAHL] |
- /***
- *
- * Bob.cp - the main routine
- *
- * Original code: Copyright (c) 1991, by David Michael Betz. All rights reserved
- * Modifications and additions: Copyright © by Christopher E. Hyde, 1995
- *
- ***/
-
- #include "Bob.h"
-
- // global variables
- char** bobargv;
- int bobargc;
-
- // forward declarations
- static void AddStream (KStr name, CStream& stream, TValue& pval);
- //static TValue AddStream (KStr name, CStream& stream);
-
-
- static char* pBuf;
- static bool pInfo;
-
-
- // The main Bob entry point
- void
- BobMain (void)
- {
- pBuf = (char*) Calloc(1024, 1);
-
- pInfo = Opt(VCompile) || Opt(DumpCode) || Opt(TraceExec);
-
- // display the banner
- if (pInfo) {
- gOutput.Put(
- "Bob v1.5.1 - Copyright © 1991, by David Michael Betz."
- " All rights reserved.\r"
- "MacBob 1.0ß2 - by Christopher E. Hyde, 1995.\r\r");
- }
-
- // initialize
- pInfo = Opt(VCompile);
- Initialize(kMaxStack);
- InitCompiler();
- bobargc = 0;
- bobargv = nil;
-
- // setup the standard i/o streams
- #if 1
- AddStream("stdin", gInput, stdin_iostream);
- AddStream("stdout", gOutput, stdout_iostream);
- AddStream("stderr", gOutput, stderr_iostream);
- #else
- stdin_iostream = AddStream("stdin", gInput);
- stdout_iostream = AddStream("stdout", gOutput);
- stderr_iostream = AddStream("stderr", gOutput);
- #endif
-
- CompileDefinitions(gInput);
- pInfo = Opt(VExec);
- Execute("main");
- }
-
-
- #if 0
- extern "C" void Abort (void);
-
- void
- Abort (void)
- {
- Fail(errUnknown);
- }
-
-
- // Compile definitions in a file
- static void
- CompileFile (KStr name)
- {
- FILE* ifp = fopen(name, "r");
- if (ifp != nil) {
- CompileDefinitions(fgetc, ifp);
- fclose(ifp);
- }
- }
- #endif
-
-
- // Display progress information
- void
- Info (KStr fmt, ...)
- {
- if (pInfo) {
- char* s = pBuf;
- *s++ = '[';
- *s++ = ' ';
-
- s += vsprintf(s, fmt, __va(fmt));
- *s++ = ' ';
- *s++ = ']';
- *s++ = '\r';
- *s = '\0';
- gOutput.Put(pBuf);
- }
- }
-
-
- // Print a formatted message to the gOutput stream and flush it immediately
- void
- PrintErrF (KStr fmt, ...)
- {
- vsprintf(pBuf, fmt, __va(fmt));
-
- gOutput.Put(pBuf);
- }
-
-
- // Print a formatted message to the gOutput stream
- void
- PrintF (KStr fmt, ...)
- {
- vsprintf(pBuf, fmt, __va(fmt));
-
- gOutput.Put(pBuf);
- }
-
-
- // Print an error message and exit
- void
- Error (KStr fmt, ...)
- {
- #if 0
- char buf1[100];
- va_list args;
-
- va_start(args, fmt);
- vsprintf(buf1, fmt, args);
- va_end(args);
- PrintErrF("Error: %s\r", buf1);
- #else
- #define buf1 &pBuf[16]
- vsprintf(buf1, fmt, __va(fmt));
- PrintErrF("Error: %s\r", buf1);
- #endif
-
- Fail(errPrintedMessage);
- }
-
-
- // Add a built-in I/O stream
- #if 1
- static void
- AddStream (KStr name, CStream& stream, TValue& pval)
- {
- extern TValue symbols;
-
- Entry sym = AddEntry(&symbols, name, stSData);
- set_iostream(&sym->fValue, NewIOStream(stream));
- pval = sym->fValue;
- }
- #else
- static TValue
- AddStream (KStr name, CStream& stream)
- {
- extern TValue symbols;
-
- Entry sym = AddEntry(&symbols, name, stSData);
- set_iostream(&sym->fValue, NewIOStream(stream));
- return sym->fValue;
- }
- #endif
-